package nyist.media.bean.auth;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import nyist.media.bean.BaseBean;
import nyist.media.entity.admin.MenuAuth;
import nyist.media.utils.DateUtil;

import java.util.Date;

/**
 * @author dcf
 * @date 2018/12/23
 */
@Getter
@Setter
@NoArgsConstructor
public class MenuAuthListBean extends BaseBean {

    private static final long serialVersionUID = 2249714478693042829L;

    /**
     * 菜单名	varchar(20)	非空
     */
    private String name;

    /**
     * 上级菜单	bigint	外键
     */
    private Long parentId;

    /**
     * 是否启用	bit(1)	非空
     */
    private boolean enabled;

    /**
     * 类型	int	非空，类型有菜单和菜单项两种
     */
    private MenuAuth.Type type;

    private boolean showMenu;

    private String href;

    private String icon;
    /**
     * 权限  varchar(50)
     */
    private String authority;

    /**
     * 创建时间
     */
    @JSONField(format = DateUtil.DATETIME_FULL_FORMATTER_STR)
    private Date createDate;

    /**
     * 修改时间
     */
    @JSONField(format = DateUtil.DATETIME_FULL_FORMATTER_STR)
    private Date modifyDate;

    private int childNum;

    private Integer orders;

    public MenuAuthListBean(MenuAuth auth) {
        setId(auth.getId());
        this.name = auth.getName();
        this.parentId = auth.getParent() != null ? auth.getParent().getId() : null;
        this.authority = auth.getAuthority();
        this.createDate = auth.getCreateDate();
        this.modifyDate = auth.getModifyDate();
        this.enabled = auth.isEnabled();
        this.type = auth.getType();
        this.childNum = auth.getChildren() != null ? auth.getChildren().size() : 0;
        this.orders = auth.getOrders();
        this.showMenu = auth.isShowMenu();
        this.href = auth.getHref();
        this.icon = auth.getIcon();
    }
}
